package cemetery.dao.impl;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

import cemetery.bean.account;
import cemetery.dao.AccountDao;
import cemetery.dao.BaseDao;

public class AccountDaoImpl extends BaseDao implements AccountDao{

	@Override
	public int denglu(account acc) {
		Connection conn=null;
		PreparedStatement stmt=null;
		ResultSet rs=null;
		int count=0;
		try {
			conn=getconnection();
			String sql=" SELECT `user`,pwd FROM account WHERE `user`= ? AND pwd= ? ";
			stmt=conn.prepareStatement(sql);
			stmt.setString(1, acc.getUser());
			stmt.setString(2, acc.getPwd());
			rs=stmt.executeQuery();
			if(rs.next()) {
				count=1;	
			}else {
				count=0;
			}
		
		} catch (Exception e) {
			// TODO: handle exception
		}finally {
			this.closeAll(conn, stmt, rs);
		}
		
		return count;
	}

	@Override
	public int zhuce(account acc) {
		String psql="INSERT INTO account (`user`,pwd,staff)VALUES(?,?,?);";
		Object []params= {acc.getUser(),acc.getPwd(),acc.getStaff()};
		int count=executeUpdate(psql, params);
		return count;
	}

	@Override
	public int update(account acc) {
		String psql="UPDATE account SET  pwd=? WHERE `user`=? AND pwd=?;";
		Object []params= {acc.getPwd(),acc.getUser(),acc.getMpwd()};
		int count=executeUpdate(psql, params);
		return count;
	}

	
}
